using System;
using System.Collections;
using System.Text;

namespace Msrp
{
    class SessionTable
    {
        public Session getSession(Msrp.Uri f_localUri, Msrp.Uri f_remoteUri)
        {            
            UriPair p = new UriPair(f_localUri, f_remoteUri);
            lock (this)
            {
                return (Session)m_uris2Session[p];
            }
        }

        public void addSession(Msrp.Uri f_localUri, Msrp.Uri f_remoteUri, Session f_session)
        {
            UriPair p = new UriPair(f_localUri, f_remoteUri);
            lock (this)
            {
                m_uris2Session.Add(p, f_session);
            }
        }



        // Singleton
        // Whatever we do with the stack we need a SessionTable, so init it statically
        public SessionTable getInstance()
        {
            return instance;
        }
        private SessionTable(){}
        static SessionTable() {}
        static readonly SessionTable instance = new SessionTable();
        // end Singleton

        private Hashtable m_uris2Session = new Hashtable();
        
        private class UriPair
        {
            public UriPair(Msrp.Uri f_localUri, Msrp.Uri f_remoteUri)
            {
                local = f_localUri;
                remote = f_remoteUri;
            }
            private Msrp.Uri local;
            private Msrp.Uri remote;
        };
    }
}
